-- scout_explore
-- Created by chengb Sep/11/2015
-- 成就：斥候探索结束

-- 内部函数声明
local whenExploreOver;

-- 注册斥候探索结束的回调
EventMgr.register("game_achievement/scout_explore", event.SCOUT_EXPLORE_OVER, function(args)
    whenExploreOver(args);
end);

-- 注册斥候探索结束的回调
whenExploreOver = function(args)
    local exploreTime = args.exploreTime or 0;
    
    -- 将秒转换成分钟
    local minutes = math.floor(exploreTime / 60);
    if minutes < 1 then
        -- 不足1分钟，无视
        return;
    end
    
    -- 判断是否是符合要求的成就
    local function isValidId(id)
        if true == GameAchievementM.isCompleted(id) then
            -- 已经完成了
            return false;
        end
        
        return true;
    end
    
    -- 遍历所有的子规则
    local ids = GameAchievementM.getIdsByRule("scout_explore");
    for _, id in pairs(ids) do
        if isValidId(id) then
            -- 尝试完成成就
            GameAchievementM.tryComplete(id, minutes);
        end
    end
end

return {
    -- 获取成就描述
    queryDesc = function(id)
        local config = GameAchievementM.query(id);

        local ruleArg  = config["rule_arg"];
        local progress = config["progress"];
        local desc     = config["desc"];
        
        desc = string.gsub(desc, "{hour}", math.floor(progress/60));

        return desc;
    end,
};